<template></template>
<script>
import { Dialog } from 'vant'
import { Toast } from 'vant'
export default {
  name,
  data() {
    return {
      activeName: 0, //控制切换界面
      MyOrderList: ['全部', '待付款', '代发货', '待收货', '待评价'],
      OrderList: {}
      // 点击当前按钮保存当前数据
    }
  },
  mounted() {
    this.activeName = this.$store.state.MyOrderStatus + 1
    this.onGetOrderList()
  },
  methods: {
    onClickLeft() {
      this.$router.back()
    },
    // 获取订单列表
    onGetOrderList() {
      this.$get('order/list', { showType: this.activeName, page: 1, limit: 10 }).then((result) => {
        console.log(result)
        this.OrderList = result.data.data.list
      })
    },
    // 取消订单
    onCancel(item) {
      Dialog.confirm({
        title: '确定取消订单？',
        message: '取消订单之后无法恢复，无法处理您的售后问题，请慎重考虑'
      })
        .then(() => {
          // on confirm
          this.$post('order/cancel', { orderId: item.id }).then((result) => {
            this.onGetOrderList()
          })
        })
        .catch(() => {
          // on cancel
        })
    },
    // 支付订单
    onPay(item) {
      Toast.loading({
        message: '加载中...',
        forbidClick: true
      })
      setTimeout(() => {
        this.$post('order/pay', { orderId: item.id }).then((result) => {
          let data = {
            PassOrderStatus: true
          }
          this.$router.push({ path: 'payment', query: data })
        })
      }, 1500)
    },
    // 删除订单设置
    onDelete(item) {
      Dialog.confirm({
        title: '确定删除订单？',
        message: '删除订单之后无法恢复，无法处理您的售后问题，请慎重考虑'
      })
        .then(() => {
          // on confirm
          this.$post('order/delete', { orderId: item.id }).then((result) => {
            console.log(result)
            this.onGetOrderList()
          })
        })
        .catch(() => {
          // on cancel
        })
    },
    // 确认收货
    onConfirm(item) {
      this.$post('order/confirm', { orderId: item.id }).then((result) => {
        Toast.success('收货成功')
        this.onGetOrderList()
      })
    },
    // 申请退款
    onRefund(item) {
      Dialog.confirm({
        title: '确定退款订单？',
        message: '退款订单之后无法恢复，无法处理您的售后问题，请慎重考虑'
      })
        .then(() => {
          // on confirm
          this.$post('order/refund', { orderId: item.id }).then((result) => {
            this.onGetOrderList()
          })
        })
        .catch(() => {
          // on cancel
        })
    },
    // 追加评价
    onRebuy(item) {
      this.$router.push('/rebuy')
      this.$store.commit('PassRebuyItem', item.goodsList)
    },
    // 查看订单
    onAftersale(item) {
      this.$router.push('/seeOreder')
      this.$store.commit('PassSeeOreder', item)
    }
  }
}
</script>
<style lang="less" scoped>
.order-centenr {
  width: 100%;
  background-color: #fff;
  margin-top: 0.1rem;
  .null {
    width: 100%;
    height: calc(100vh -90px);
    background-color: red;
  }
  .div {
    padding: 0.1rem;
    .order-centenr-order {
      p {
        line-height: 0.4rem;
        span {
          float: right;
          color: #bb4141;
        }
      }
    }
    .order-centenr-order-goods {
      border-top: 0.01rem solid #f2f3f3;
      border-bottom: 0.01rem solid #f2f3f3;

      padding: 0.1rem 0rem;
      .goods-details-img {
        img {
          width: 100%;
          background-color: #f2f3f3;
        }
      }
      .goods-details-text {
        padding: 0.1rem;
        p:nth-child(1) {
        }
        p:nth-child(2) {
          font-size: 14px;
          opacity: 0.5;
          padding: 0.05rem 0rem;
        }
        p:nth-child(3) {
          opacity: 0.5;
          float: right;
          font-size: 14px;
        }
      }
    }
    .goods-Price {
      line-height: 0.4rem;
      .btn {
        float: right;
        margin-top: -0.05rem;
      }
    }
  }
}
</style>
